<template>
    <div>
        <el-table :data="classsifys" style="width: 100%">
            <el-table-column label="产品分类名称" width="180">
                <template slot-scope="scope">
                    <el-popover trigger="hover" placement="top">
                        <p>产品分类名称: {{ scope.row.name }}</p>
                        <div slot="reference" class="name-wrapper">
                            <el-tag size="medium">{{ scope.row.name }}</el-tag>
                        </div>
                    </el-popover>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        @click="handleChange(scope.$index, scope.row)"
                        >修改</el-button
                    >

                    <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)"
                        >删除</el-button
                    >
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <span class="demonstration">调整每页显示条数</span>
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page.sync="currentPage"
                :page-sizes="[3, 5, 7]"
                :page-size="3"
                layout="sizes, prev, pager, next"
                :total="total"
            >
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
let { mapActions, mapState } = createNamespacedHelpers("classifysList");
export default {
    computed: {
        // 渲染列表   总数据
        ...mapState(["classsifys", "total"]),
    },
    mounted() {
        this.getClassifys({
            currentPage: this.currentPage,
            pageSize: this.pageSize,
        });
    },
    data() {
        return {
            currentPage: 1,
            pageSize: 3,
        };
    },
    methods: {
        //删除
        handleDelete(index, row) {
            this.deleteClassifys({ _id: row._id });
            this.getClassifys({
                pageSize: this.pageSize,
                currentPage: this.currentPage,
            });
        },
        //改变最大显示条数
        handleSizeChange(val) {
            this.pageSize = val;
            this.getClassifys({
                pageSize: this.pageSize,
                currentPage: this.currentPage,
            });
        },
        //改变当前页
        handleCurrentChange(val) {
            this.currentPage = val;
            this.getClassifys({
                currentPage: this.currentPage,
                pageSize: this.pageSize,
            });
        },
        //跳转修改界面
        handleChange(index, row) {
            this.$router.push("/system/classifysChange/" + row._id);
        },
        ...mapActions(["getClassifys", "deleteClassifys"]),
    },
};
</script>
<style scoped lang=scss>
.block {
    height: 100px;
    line-height: 90px;
}
</style>